/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIMantenimientoCliente2.java
 *
 * Created on Oct 19, 2011, 8:20:09 AM
 */
package GUI.Contactos;

import BE.BEContacto;
import BL.BLCombo;
import BL.BLContacto;
import BL.BLModelo;
import BL.BLValidaciones;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.data.JRTableModelDataSource;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.JRLoader;
import org.apache.poi.hssf.util.HSSFColor.BLACK;


/**
 *
 * @author slayer
 */
public class GUIMantenimientoContacto extends javax.swing.JDialog {
Boolean busqueda;
BEContacto objEmpleado;
int modo=0;
    public JComboBox getCmbTipoContacto() {
        return cmbTipoContacto;
    }

    public void setCmbTipoContacto(JComboBox cmbTipoContacto) {
        this.cmbTipoContacto = cmbTipoContacto;
    }

    public BEContacto getObjEmpleado() {
        return objEmpleado;
    }

    public void setObjEmpleado(BEContacto objEmpleado) {
        this.objEmpleado = objEmpleado;
    }
    /** Creates new form GUIMantenimientoCliente2 */


  public GUIMantenimientoContacto(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        
        this.setLocationRelativeTo(null);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int height = screenSize.height;
        int width = screenSize.width;
        this.setLocation(width/2-this.getWidth()/2, height/2-this.getHeight()/2);
        
        BLValidaciones validar = new BLValidaciones();
        this.txtCodContacto.addKeyListener(validar.soloNumeros);
        
        busqueda=false;
        this.inicializa();
    }

     public GUIMantenimientoContacto(java.awt.Frame parent, boolean modal, BEContacto contacto,int modo) {
        super(parent, modal);
        initComponents();
        
        this.setLocationRelativeTo(null);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int height = screenSize.height;
        int width = screenSize.width;
        this.setLocation(width/2-this.getWidth()/2, height/2-this.getHeight()/2);
        
        BLValidaciones validar = new BLValidaciones();
        this.txtCodContacto.addKeyListener(validar.soloNumeros);
        this.modo=modo;
        this.inicializa();
        objEmpleado=contacto;
        busqueda= true;
        if (busqueda) this.modoBusqueda();

        }

       public GUIMantenimientoContacto(java.awt.Frame parent, boolean modal, BEContacto contacto) {
            super(parent, modal);
            initComponents();

            this.setLocationRelativeTo(null);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            int height = screenSize.height;
            int width = screenSize.width;
            this.setLocation(width/2-this.getWidth()/2, height/2-this.getHeight()/2);


            BLValidaciones validar = new BLValidaciones();
            this.txtCodContacto.addKeyListener(validar.soloNumeros);

            this.inicializa();
            objEmpleado=contacto;
            busqueda= true;
            if (busqueda) this.modoBusqueda();

        }



    private void modoBusqueda() {
        btnAgregar.setVisible(false);
        btnEditar.setVisible(false);
        btnEliminar.setText("Aceptar");
        cmbEstado.setSelectedIndex(1);
        cmbEstado.setEnabled(false);
            if (modo==1)
                cmbTipoContacto.setSelectedIndex(1);
            else
        cmbTipoContacto.setSelectedIndex(2);

        cmbTipoContacto.setEnabled(false);
    }

    public void inicializa()
    {
        
       BLContacto blContacto = new BLContacto();
       blContacto.setTipoContactoMant(this.cmbTipoContacto);
       
       
        cmbEstado.addItem(new BLCombo(2,"TODOS"));
        cmbEstado.addItem(new BLCombo(1,"ACTIVO"));
        cmbEstado.addItem(new BLCombo(0,"INACTIVO"));
        
        blContacto.setTipoDocumento(this.cmbTipoDocumento); 
   
        //BLModelo modelo = new BLModelo();
        //tblContacto.setModel(modelo);

        //modelo.addColumn("Código");
        //modelo.addColumn("Empresa");
        //modelo.addColumn("Tipo Contacto");
        //modelo.addColumn("Tipo Documento");
        //modelo.addColumn("Estado");
        //modelo.addColumn("Nombre");
        //modelo.addColumn("Apellido Paterno");
              
                        
        //blContacto.limpiaTabla(tblContacto);
        //blContacto.buscaContacto(0,0,"","", "",0,"", this.tblContacto,0);
    
       
    
//        
        
        
        
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlBusqueda = new javax.swing.JPanel();
        btnFiltrar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        lblCodEmpleado = new javax.swing.JLabel();
        txtCodContacto = new javax.swing.JTextField();
        lblTipoContacto = new javax.swing.JLabel();
        cmbTipoContacto = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        cmbEstado = new javax.swing.JComboBox();
        cmbTipoDocumento = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblID = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        lblEstado = new javax.swing.JLabel();
        txtApePaterno = new javax.swing.JTextField();
        lblApeMaterno = new javax.swing.JLabel();
        txtApeMaterno = new javax.swing.JTextField();
        txtNombEmpresa = new javax.swing.JTextField();
        lblZona1 = new javax.swing.JLabel();
        btnLimpiar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblContacto = new javax.swing.JTable();
        pnlBotones = new javax.swing.JPanel();
        btnEditar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnAgregar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Administrar Contactos");

        pnlBusqueda.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Empleado"));
        pnlBusqueda.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        pnlBusqueda.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);

        btnFiltrar.setText("Filtrar");
        btnFiltrar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnFiltrar.setMinimumSize(new java.awt.Dimension(100, 25));
        btnFiltrar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnFiltrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFiltrarActionPerformed(evt);
            }
        });

        lblCodEmpleado.setText("Código:");

        txtCodContacto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCodContactoKeyTyped(evt);
            }
        });

        lblTipoContacto.setText("Tipo Contacto:");

        jLabel1.setText("Estado:");

        jLabel2.setText("Tipo Documento:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(cmbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblCodEmpleado)
                        .addGap(85, 85, 85)
                        .addComponent(txtCodContacto, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(152, 152, 152))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(lblTipoContacto)
                        .addGap(35, 35, 35)
                        .addComponent(cmbTipoContacto, 0, 267, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(85, 85, 85)
                        .addComponent(cmbEstado, 0, 268, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCodEmpleado)
                    .addComponent(txtCodContacto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbTipoContacto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTipoContacto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(65, 65, 65))
        );

        lblID.setText("Nombre:");

        lblEstado.setText("Apellido Paterno:");

        lblApeMaterno.setText("Apellido Materno:");

        lblZona1.setText("Nombre Empresa:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblID)
                    .addComponent(lblEstado)
                    .addComponent(lblApeMaterno)
                    .addComponent(lblZona1))
                .addGap(34, 34, 34)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNombEmpresa, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                    .addComponent(txtApePaterno, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                    .addComponent(txtApeMaterno, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNombEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblZona1))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblID))
                .addGap(16, 16, 16)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEstado)
                    .addComponent(txtApePaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtApeMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblApeMaterno))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        btnLimpiar.setText("Limpiar");
        btnLimpiar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnLimpiar.setMinimumSize(new java.awt.Dimension(100, 25));
        btnLimpiar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBusquedaLayout = new javax.swing.GroupLayout(pnlBusqueda);
        pnlBusqueda.setLayout(pnlBusquedaLayout);
        pnlBusquedaLayout.setHorizontalGroup(
            pnlBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBusquedaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(pnlBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlBusquedaLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(pnlBusquedaLayout.createSequentialGroup()
                        .addGap(190, 190, 190)
                        .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27))))
        );
        pnlBusquedaLayout.setVerticalGroup(
            pnlBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBusquedaLayout.createSequentialGroup()
                .addGroup(pnlBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlBusquedaLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(pnlBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        tblContacto.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblContacto.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jScrollPane1.setViewportView(tblContacto);

        btnEditar.setText("Editar");
        btnEditar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnEditar.setMinimumSize(new java.awt.Dimension(70, 30));
        btnEditar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        btnEliminar.setText("Eliminar");
        btnEliminar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnEliminar.setMinimumSize(new java.awt.Dimension(70, 30));
        btnEliminar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnCancelar.setMinimumSize(new java.awt.Dimension(70, 30));
        btnCancelar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnAgregar.setText("Agregar");
        btnAgregar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnAgregar.setMinimumSize(new java.awt.Dimension(70, 30));
        btnAgregar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBotonesLayout = new javax.swing.GroupLayout(pnlBotones);
        pnlBotones.setLayout(pnlBotonesLayout);
        pnlBotonesLayout.setHorizontalGroup(
            pnlBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBotonesLayout.createSequentialGroup()
                .addContainerGap(25, Short.MAX_VALUE)
                .addComponent(btnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pnlBotonesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnAgregar, btnCancelar, btnEditar, btnEliminar});

        pnlBotonesLayout.setVerticalGroup(
            pnlBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlBotonesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnAgregar, btnCancelar, btnEditar, btnEliminar});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pnlBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pnlBusqueda, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 885, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        // TODO add your handling code here:
        
        GUIAgregarContacto frmAgregarContacto = new GUIAgregarContacto(null,true);
        frmAgregarContacto.setVisible(true);
        
        BLContacto blContacto = new BLContacto();
        blContacto.limpiaTabla(tblContacto);
        blContacto.buscaContacto(0,0,"","", "",0,"ACTIVO", this.tblContacto,0);
        
}//GEN-LAST:event_btnAgregarActionPerformed

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_btnCancelarActionPerformed

private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
// TODO add your handling code here:
    //GUIModificarContacto frmModificarContacto = new GUIModificarContacto(null,true);
    //frmModificarContacto.setVisible(true);
    
     int fila,numFilas;
     int columna = 0; //Columna ID
     int IDProd;
     
     numFilas = this.tblContacto.getSelectedRowCount();
     if (numFilas == 1){
        fila = this.tblContacto.getSelectedRow();
        if (JOptionPane.showConfirmDialog(null,"Desea editar el contacto?",
                 "Confirmación",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE) == 0)
        {
             IDProd = Integer.parseInt(this.tblContacto.getModel().getValueAt(fila,columna).toString());
        
             GUIModificarContacto frmModificarContacto = new GUIModificarContacto(null, true,IDProd);
             frmModificarContacto.setResizable(false);
             frmModificarContacto.setVisible(true);

             BLContacto blContacto = new BLContacto();
             blContacto.limpiaTabla(tblContacto);
             blContacto.buscaContacto(0,0,"","", "",0,"ACTIVO", this.tblContacto,0); //PARA BUSCAR TODOS LOS PRODUCTOS
        
        
        
        }
     
     }
     else 
         JOptionPane.showMessageDialog(null,"Debe seleccionar un contacto para editar",
                                          "Error",JOptionPane.ERROR_MESSAGE);
    
     
    
}//GEN-LAST:event_btnEditarActionPerformed

private void btnFiltrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFiltrarActionPerformed
        
        BLContacto blContacto = new BLContacto();
        BLValidaciones validar = new BLValidaciones();
        
        int codigo;
               
        if (!"".equals(this.txtCodContacto.getText().toString())) 
            codigo = Integer.parseInt(this.txtCodContacto.getText());
        else
            codigo =0;
        
        //if (!"".equals(this.pnlTipoDocumento.getComponent(1).getText().toString())) 
          //  dni = Integer.parseInt(this.txtDni.getText());
        //else
          //  dni =0;
        
        //if (!"".equals(this.txtRuc.getText().toString())) 
        //    ruc = Integer.parseInt(this.txtRuc.getText());
        //else
        //   ruc =0;
        
        BLCombo idTipoDoc = (BLCombo)cmbTipoDocumento.getSelectedItem();
        BLCombo idTipo = (BLCombo)cmbTipoContacto.getSelectedItem();
        BLCombo idEstado = (BLCombo)cmbEstado.getSelectedItem();
        
        blContacto.buscaContacto(codigo,idTipoDoc.id,validar.validarSqlInjection(this.txtNombEmpresa.getText()),validar.validarSqlInjection(this.txtNombre.getText()),
         validar.validarSqlInjection(this.txtApePaterno.getText()),idTipo.id,idEstado.nombre, this.tblContacto,1); //1 = busqueda por paramtros
    // TODO add your handling code here:
      
        
        
}//GEN-LAST:event_btnFiltrarActionPerformed

private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        BLContacto blContacto = new BLContacto();

        blContacto.limpiaTabla(this.tblContacto);
       
        this.cmbTipoDocumento.setSelectedIndex(0);
        
        if (!busqueda)
        {
            this.cmbEstado.setSelectedIndex(0);
         this.cmbTipoContacto.setSelectedIndex(0);}

        this.txtApeMaterno.setText("");
        this.txtApePaterno.setText("");
        this.txtNombre.setText("");
        this.txtCodContacto.setText("");
            
        
    // TODO add your handling code here:
}//GEN-LAST:event_btnLimpiarActionPerformed

private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed


    if (busqueda)
    {
        BLContacto objGestorEmpleado = new BLContacto();
        objEmpleado= objGestorEmpleado.llenaVentana(Integer.parseInt(tblContacto.getModel().getValueAt(tblContacto.getSelectedRow(),0).toString()));
        
        this.setVisible(false);
    }
    else{
    int fila;
        int columna = 0,numFilas; //Columna ID
        int IDPrueba=0, vretorno = 1;
        BLContacto bLContacto = new BLContacto();
        
        numFilas = tblContacto.getSelectedRowCount();
        fila = tblContacto.getSelectedRow();
        if ( numFilas != 1 )
        {
            JOptionPane.showMessageDialog(null,"Debe seleccionar un contacto para eliminar",
                                          "Error",JOptionPane.ERROR_MESSAGE);
        }  
            
        else if (tblContacto.getModel().getValueAt(fila,5).toString().equals("INACTIVO")){
                
            JOptionPane.showMessageDialog(null,"El contacto ya se encuentra INACTIVO",
                                          "Error",JOptionPane.ERROR_MESSAGE);
        }
        else if (JOptionPane.showConfirmDialog(null,"Desea eliminar el contacto?",
                 "Confirmación",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE) == 0)
        {
            IDPrueba = Integer.parseInt(tblContacto.getModel().getValueAt(fila,columna).toString());
            vretorno = bLContacto.eliminarContacto(IDPrueba, tblContacto);
        }
        
        if (vretorno == 0)
        {
            
            BL.BLLogAudit objGestorLog= new BL.BLLogAudit();
            BE.BELogAudit auxLogAudit= new BE.BELogAudit();
            auxLogAudit.setIdInterface(0);
            auxLogAudit.setIdUsuario(BL.BLCardex.getObjUsuario().getIdUsuario());
            BEContacto auxContacto = bLContacto.llenaVentana(IDPrueba);
            auxLogAudit.setAccion("Eliminacion del Contacto "+ auxContacto.getApePaterno()+" "+auxContacto.getApeMaterno()+", "+auxContacto.getNombre() +" por el usuario "+BL.BLCardex.getObjUsuario().getUsuario()+"." );
            java.util.Date aux= new java.util.Date();
            java.sql.Timestamp fecha= new java.sql.Timestamp(aux.getTime());
            
            JOptionPane.showMessageDialog(null,"Se eliminó el contacto",
                                          "Información",JOptionPane.INFORMATION_MESSAGE);
            bLContacto.limpiaTabla(tblContacto);
            bLContacto.buscaContacto(0,0,"","","",0,"ACTIVO", this.tblContacto,0);
        }
        
        
        
      

           
                
        
        
            
        
    }
}//GEN-LAST:event_btnEliminarActionPerformed

private void txtCodContactoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCodContactoKeyTyped
    if (this.txtCodContacto.getText().length()>7)
	evt.consume();
    // TODO add your handling code here:
}//GEN-LAST:event_txtCodContactoKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUIMantenimientoContacto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUIMantenimientoContacto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUIMantenimientoContacto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUIMantenimientoContacto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                GUIMantenimientoContacto dialog = new GUIMantenimientoContacto(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnFiltrar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JComboBox cmbTipoContacto;
    private javax.swing.JComboBox cmbTipoDocumento;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblApeMaterno;
    private javax.swing.JLabel lblCodEmpleado;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblID;
    private javax.swing.JLabel lblTipoContacto;
    private javax.swing.JLabel lblZona1;
    private javax.swing.JPanel pnlBotones;
    private javax.swing.JPanel pnlBusqueda;
    private javax.swing.JTable tblContacto;
    private javax.swing.JTextField txtApeMaterno;
    private javax.swing.JTextField txtApePaterno;
    private javax.swing.JTextField txtCodContacto;
    private javax.swing.JTextField txtNombEmpresa;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables
}
